<?php

class Application_Model_DbTable_WayWeight extends Application_Model_DbTable_DomainObject{

    protected $_name = 'uuch_wayWeight';
    
    public function getMapper() {
        return array('id','wayId','weight','type');
    }
    
    public function getSumWeightByTypeOperator($operateType,$operator,$type,$weightType,$startDate,$endDate)
    {
        $db = $this->getAdapter();
        $sql = "SELECT sum(ww.weight) as num FROM uuch_wayWeight as ww ";
        $sql.= " JOIN uuch_waybill as wb ON ww.wayId = wb.id ";
        $sql.= $db->quoteInto(" and wb.dateSend >= ?", $startDate." 00:00:00");
        $sql.= $db->quoteInto(" and wb.dateSend <= ?", $endDate." 23:59:59");
        $sql .= " JOIN uuch_wayLog as wl ON ww.wayId = wl.wayId ";
        $sql.= $db->quoteInto(" and wl.operateType = ?", $operateType);
        $sql.= $db->quoteInto(" and wl.type = ?", $type);
        if($operator != ""){
            $sql.= $db->quoteInto(" and wl.operator = ?", $operator);
        }
        $sql.= $db->quoteInto(" where ww.type = ?", $weightType);
        
        $row = $db->fetchRow($sql);
        return $row["num"];
    }
}